﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="ListAgents.aspx.cs" Inherits="ListAgents" %>

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Store1.DataSource = new List<Company> 
         { 
             new Company("asdaer","Jason Hetfield", "05443454333", "Agent", 0.03),
             new Company("asdfaf","Paul Cezanne", "05443454333", "Agent", 1.47),
             new Company("adasee","Marleu Ponty", "05443454333", "Agent", 0.34),
             new Company("asfsdf","Donald Trump", "05443454333", "Agent", 0.02),
             new Company("xcvxcv","Kazimir Malevich", "05443454333", "Agent", 0.49),
             new Company("asgfd","Gilles Deleuze", "05443454333", "Administrator", -1.54),
             new Company("xzcas","Michel Foucault", "05443454333", "Agent", 0.71),
             new Company("bghfgh","Evelyn Reed", "05443454333", "Agent", 1.39),
             
         };

        this.Store1.DataBind();
    }

    public class Company
    {
        public Company(string username, string name, string price, string role, double pctChange)
        {
            this.Username = username;
            this.Name = name;
            this.Price = price;
            this.Role = role;
            this.PctChange = pctChange;
        }


        public string Username { get; set; }
        public string Name { get; set; }
        public string Price { get; set; }
        public string Role { get; set; }
        public double PctChange { get; set; }
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <script type="text/javascript">
        var template = '<span style="color:{0};">{1}</span>';

        var change = function (value) {
            return String.format(template, (value > 0) ? "green" : "red", value);
        };

        var pctChange = function (value) {
            return String.format(template, (value > 0) ? "green" : "red", value + "%");
        };
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <ext:Store ID="Store1" runat="server">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="Username" />
                    <ext:RecordField Name="Name" />
                    <ext:RecordField Name="Price" />
                    <ext:RecordField Name="Role" />
                    <ext:RecordField Name="PctChange" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" StripeRows="true"
        Title="Agent List" PaddingSummary="5px 5px 0" Width="790px" Height="350" AutoExpandColumn="Company">
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:Column ColumnID="Company" Header="Agent" Width="150" DataIndex="Name" />
                <ext:Column ColumnID="Company" Header="Username" Width="50" DataIndex="Username" />
                <ext:Column Header="Phone" Width="120" DataIndex="Price">
                </ext:Column>
                <ext:Column Header="Role" Width="75" DataIndex="Role">
                    <Renderer Fn="change" />
                </ext:Column>
                <%-- <ext:Column Header="Change" Width="75" DataIndex="PctChange">
                    <Renderer Fn="pctChange" />
                </ext:Column>--%>
            </Columns>
        </ColumnModel>
        <TopBar>
            <ext:Toolbar ID="Toolbar1" runat="server">
                <Items>
                    <ext:Button ID="Button1" runat="server" Text="Add" Icon="Add">
                        <Listeners>
                            <Click Handler="Ext.Msg.alert('Confirm', 'You Clicked Add');" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button2" runat="server" Text="Delete" Icon="Exclamation">
                        <Listeners>
                            <Click Handler="Ext.Msg.confirm('Delete Agent', 'Are you sure?');" />
                            <%-- çalışmazzz --%>
                            <%--Ext.Msg.alert('Click','Click on Delete');  --%>
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button3" runat="server" Text="View" Icon="User">
                        <Listeners>
                            <Click Handler="Ext.Msg.alert('Confirm', 'You Clicked View');" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="Button4" runat="server" Text="Edit" Icon="Pencil">
                        <Listeners>
                            <Click Handler="Ext.Msg.alert('Confirm', 'You Clicked Edit');" />
                        </Listeners>
                    </ext:Button>
                </Items>
            </ext:Toolbar>
        </TopBar>
    </ext:GridPanel>
</asp:Content>
